package pl.edu.agh.hollonCommision.graph.connectionModel;

import dtp.commission.Commission;

public class LocationProximityConnection implements IConnectionModel {

	private double distance;
	
	public LocationProximityConnection(double distance) {
		this.distance = distance;
	}
	
	@Override
	public boolean areConnected(Commission commission, Commission commission2) {
		double tmpDistance;
		double x = commission.getPickupX() - commission2.getPickupX();
		double y = commission.getPickupY() - commission2.getPickupY();
		tmpDistance = x * x + y * y;

		x = commission.getPickupX() - commission2.getDeliveryX();
		y = commission.getPickupY() - commission2.getDeliveryY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		
		x = commission.getDeliveryX() - commission2.getPickupX();
		y = commission.getDeliveryY() - commission2.getPickupY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		
		x = commission.getDeliveryX() - commission2.getDeliveryX();
		y = commission.getDeliveryY() - commission2.getDeliveryY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		
		return (Math.sqrt(tmpDistance) < distance );
	}
}
